<?php

abstract class Base_Block
{
    protected $_dbTable  = null;

	
    public function getDbTable()
    {
        if (null === $this->_dbTable) {
            $this->_dbTable = new $this->_tableName();
        }

        return $this->_dbTable;
    }
    
	public function readBy($key, $val)
	{
        $resultRow = $this->getDbTable()->readBy($key, $val);
        if (!$resultRow) {
            throw new Base_Model_Exception(
               'Model not exist', 404
            );
        }
        
        $this->setEntry($resultRow);
        return $this;
	}
	
	public function read($id)
	{
        $resultRow = $this->getDbTable()->read($id);
        if (!$resultRow) {
            throw new Base_Model_Exception(
               'Model not exist', 404
            );
        }
        
        $this->setEntry($resultRow->toArray());
        return $this;
	}
	
	public function view(array $where= NULL, $order= NULL, $count= NULL, $offset= NULL)
    {
        return $this->getDbTable()->view($where, $order, $count, $offset);
    }
}